﻿using NUglify;
using PLCS.Application.Contracts.ErrorLibraryApp.Dtos;
using PLCS.Application.Contracts.PLCReadDataApp.Dtos;
using PLCS.Client.IService.ConfigManager;
using Volo.Abp.Application.Dtos;

namespace PLCS.Client.Service.ConfigManager;

public class ErrorLibraryService : BaseService<ErrorLibraryDto, ErrorLibraryEditDto>, IErrorLibraryService
{
    public async Task<PagedResultDto<ErrorLibraryDto>> GetListBySearchAsync(int skipCount, int maxResultCount, string? code, string? kind, string? source)
    {
        var route = $"errorLibrary/bySearch?SkipCount={skipCount}&MaxResultCount={maxResultCount}";
        if (!string.IsNullOrEmpty(code))
            route += $"&code={code}";
        if (!string.IsNullOrEmpty(kind))
            route += $"&kind={kind}";
        if (!string.IsNullOrEmpty(source))
            route += $"&source={source}";

        RequestParam requestParam = new(method: Method.Get, route: route);
        var apiRes = await restClient.ExecuteAsync<PagedResultDto<ErrorLibraryDto>>(requestParam);
        if (apiRes.Status)
            return apiRes.Data;
        else
            return new PagedResultDto<ErrorLibraryDto>();
    }
}